package com.example.basic.utils;

import android.util.Log;

import java.util.Map;

public class ProcessUtils {

    private static final String TAG = "ProcessUtils";

    public static void getAllThread() {
        Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
        Log.d(TAG, "线程总数：" + allStackTraces.size());
        for (Map.Entry<Thread, StackTraceElement[]> stackTrace : allStackTraces.entrySet()) {
            Thread thread = (Thread) stackTrace.getKey();
            Log.d(TAG, "线程：" + thread.getName() + ",id=" + thread.getId() + ",state=" + thread.getState());
//            StackTraceElement[] stack = (StackTraceElement[]) stackTrace.getValue();
//            String strStackTrace = "堆栈：";
//            for (StackTraceElement stackTraceElement : stack) {
//                strStackTrace += stackTraceElement.toString() + "\n";
//            }
//            Log.d(TAG, strStackTrace);
        }
    }
}
